using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.ComponentModel
{
    [TestClass]
    public class WhenFindingInSortableBindingLists
    {
        [TestMethod]
        public void ShouldReturnIndexOfItemWithAddress2()
        {
            IBindingList bindingList = SortableBindingListFactory.Create();
            PropertyDescriptor propertyDescriptor = PropertyDescriptorHelper.Get(bindingList[0], "Address");
            bindingList.ApplySort(propertyDescriptor, ListSortDirection.Descending);

            object key = new GenericComparableAddress("2");
            int actual = bindingList.Find(propertyDescriptor, key);

            int expected = 1;

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ShouldReturnMinusOneWhenItemIsNotFound()
        {
            IBindingList bindingList = SortableBindingListFactory.Create();
            PropertyDescriptor propertyDescriptor = PropertyDescriptorHelper.Get(bindingList[0], "Address");
            bindingList.ApplySort(propertyDescriptor, ListSortDirection.Descending);

            object key = new GenericComparableAddress("4");
            int actual = bindingList.Find(propertyDescriptor, key);

            int expected = -1;

            Assert.AreEqual(expected, actual);
        }
    }
}